<?php

class Gallery {

    private $id;
    private $title;
    private $description;
    private $folder;
    private $date;
    private $path;
    private $visible;
    private $creator;
    private $photos;
    
    public function __construct() {
        $this->title = '';
        $this->description = '';
        $this->date = null;
        $this->path = '';
        $this->visible = false;
        $this->photos = null;
            
    }

    public function __get($property) {
        return $this->{$property};
    }

    public function __set($property, $value) {
        $this->{$property} = $value;
    }

    public function get_link() {
        return 'http://www.salesianichioggia.it/photos/' . $this->date->format('Y') . '/' . $this->date->format('m') . '/' . $this->path . '/';
    }
    
    public function get_thumbnails_path() {
        return 'http://www.salesianichioggia.it/photos/' . $this->date->format('Y') . '/' . $this->date->format('m') . '/' . $this->path . '/thumbnails/';
    }
    
    public function get_photos_path() {
        return 'http://www.salesianichioggia.it/photos/' . $this->date->format('Y') . '/' . $this->date->format('m') . '/' . $this->path . '/photos/';
    }

    public function get_list_html() {
        ?>
        <tr>
            <td><strong><?= $this->title ?></strong></td>
            <td><?= $this->description ?></td>
            <td><?= $this->date->format('d/m/Y') ?></td>
            <td><?= $this->path ?></td>
            <td>
                <div class="btn-group">
                    <a class="btn" href="http://www.salesianichioggia.it/dashboard/gallery.php?action=edit&id=<?= $this->id ?>"><i class="icon-pencil"></i></a>
                    <a class="btn btn-danger delete" href="http://www.salesianichioggia.it/dashboard/gallery.php?action=delete&id=<?= $this->id ?>"><i class="icon-trash"></i></a>
                </div>
            </td>
        </tr>

        <?php
    }
    
    public function get_html_view() { ?>
        <h1 class="gallery-title"><?= $this->title ?></h1>
        <ul class="thumbnails">
            <?php 
                foreach ($this->photos as $photo) { ?>
                    <li class="span3">
                        <a class="thumbnail fresco" data-fresco-group="gallery" href="<?= $this->get_photos_path() . $photo->url ?>"><img src="<?= $this->get_thumbnails_path() . $photo->url ?>" alt="" /></a>
                    </li>
            <?php
                }
            ?>
        </ul>
        <p>&copy; Le foto qui presenti sono ad uso esclusivo dell'Oratorio Salesiano di Chioggia. Non è permesso l'uso a terzi 
(per stampa, pubblicazione su altri siti web o realizzazione di video) senza previa richiesta e conseguente autorizzazione.</p>
    <?php 
    }
    
    
    public function get_seo_link() {
        $seo = "";
        $array = explode(" ", self::escape_string($this->title));
        foreach ($array as $value) {
            if ($value != "")
                $seo .= $value . '-';
        }

        $seo .= $this->id . ".html";
        return strtolower($seo);
    }

    public static function escape_string($string) {
        $escaping_chars = array("à", "á", "è", "é", "ì", "í", "ò", "ó", "ù", "ú", "/", "°", ",", ".", ":", ";", "?", "!", "-", "\n", "'", "+", "(", ")", '"');
        $replacing_chars = array("a", "a", "e", "e", "i", "i", "o", "o", "u", "u", " ", "", "", "", "", "", "", "", "", " ", " ", " ", " ", " ");
        return str_replace($escaping_chars, $replacing_chars, $string);
    }
}
?>